package org.goldfish.mapreduce.orders;

import lombok.*;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class OrderKey implements WritableComparable<OrderKey>,Comparable<OrderKey> {

    String  userId;
    String  orderTime;
    public int compareTo(OrderKey o) {
        int result = userId.compareTo(o.userId);
        if (result != 0) {
            return result;
        }
        return orderTime.compareTo(o.orderTime);
    }
    public void write(java.io.DataOutput out) throws java.io.IOException {
        Text.writeString(out, userId==null?"":userId);
        Text.writeString(out, orderTime==null?"":orderTime);
    }
    public void readFields(java.io.DataInput in) throws java.io.IOException {
        userId = Text.readString(in);
        orderTime = Text.readString(in);
    }
}
